package com.goldfish666.remote_control;

import lombok.extern.slf4j.Slf4j;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.nio.charset.StandardCharsets;

@Slf4j
public class SendTest {

    private static String powerSwitchOn = "s 0 1 0 1 0 1 1 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 e";

    private static String powerSwitchOn1 = "2 2 0 1 0 1 0 1 1 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 2 2 0 1 0 1 0 1 1 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1";

    private static String test = "2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1";
    private static byte[] buff = new byte[124];


    private static byte[] getBytes() {
        return powerSwitchOn.replace(" ", "").getBytes(StandardCharsets.UTF_8);
//        List<Byte> list = Arrays.stream(powerSwitchOn.split(" ")).map(x -> (byte) Integer.parseInt(x)).collect(Collectors.toList());
//        int size = list.size() / 8;
//        byte[] result = new byte[size];
//        for (int i = 0; i < size; i++) {
//            byte b = (byte) 0;
//            for (int j = 0; j < 8; j++) {
//                int index = i * 8 + 7 - j;
////                byte x = (byte) (b << 1);
//                b = (byte) (b << 1 | list.get(index));
//            }
//            result[i] = b;
//        }
//        return result;
    }

    private static void setBuff() {
        byte[] x = getBytes();
        for (int i = 0; i < x.length; i++) {
            buff[i] = x[i];
        }
    }

    public static void main(String[] args) throws Exception {

        setBuff();
//115 106 46 0 0 -124 0 0 0 0 0 0 0 0 0 -104 101
        // 73 6A 2e
        DatagramSocket socket = new DatagramSocket();
//        byte[] buf = "ge men lai le".getBytes();
        //将数据打包
        DatagramPacket packet = new DatagramPacket(buff, buff.length, InetAddress.getByName("192.168.0.101"), 1002);
        socket.send(packet);
        socket.close();

    }
}
